﻿using JAAF;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace JAAF.Builders.Test
{
    
    
    /// <summary>
    ///This is a test class for ObjectFactoryTest and is intended
    ///to contain all ObjectFactoryTest Unit Tests
    ///</summary>
    [TestClass()]
    public class ObjectFactoryTest
    {
        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for Create
        ///</summary>
        public void CreateTestHelper<TAbstraction>()
            where TAbstraction : new()
        {
            object[] _aoConstructorParams = null; // TODO: Initialize to an appropriate value
            object expected = null; // TODO: Initialize to an appropriate value
            object actual;
            actual = ObjectFactory.Create<TAbstraction>(_aoConstructorParams);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }

        [TestMethod()]
        public void CreateTest()
        {
            CreateTestHelper<GenericParameterHelper>();
        }

        /// <summary>
        ///A test for the non-generic Create method
        ///</summary>
        [TestMethod()]
        public void ObjectFactory_CreateNonGenericParameterless()
        {
            string _sAbstraction = "JAAF.Builders.Test.TestTypes.EventLoggerBase_TestClass";
            Type expectedType = typeof(JAAF.Builders.Test.TestTypes.FileEventLogger_TestClass);
            object actual;
            actual = ObjectFactory.Create(_sAbstraction);
            Assert.AreEqual(expectedType.FullName, actual.GetType().FullName);
        }

        /// <summary>
        ///A test for the generic Create method
        ///</summary>
        [TestMethod()]
        public void ObjectFactory_CreateGenericParameterless()
        {
            Type expectedType = typeof(JAAF.Builders.Test.TestTypes.FileEventLogger_TestClass);
            object actual;
            actual = ObjectFactory.Create<JAAF.Builders.Test.TestTypes.EventLoggerBase_TestClass>();
            Assert.AreEqual(expectedType.FullName, actual.GetType().FullName);
        }

        /// <summary>
        ///A test for LoadConfiguration
        ///</summary>
        [TestMethod()]
        [DeploymentItem("JAAF.Builders.dll")]
        public void ObjectFactory_LoadConfigurationTest()
        {
            ObjectFactory_Accessor.LoadConfiguration();
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }

        [TestMethod()]
        [DeploymentItem("JAAF.Builders.dll")]
        public void ObjectFactory_IsRegisteredTest()
        {
            bool bResult = ObjectFactory.IsRegistered("NonExistentAbstraction");
            Assert.IsFalse(bResult);

            bResult = ObjectFactory.IsRegistered("JAAF.Builders.Test.TestTypes.EventLoggerBase_TestClass");
            Assert.IsTrue(bResult);

            bResult = ObjectFactory.IsRegistered(typeof(JAAF.Builders.Test.TestTypes.IUnimplemented_TestInterface));
            Assert.IsFalse(bResult);

            bResult = ObjectFactory.IsRegistered(typeof(JAAF.Builders.Test.TestTypes.EventLoggerBase_TestClass));
            Assert.IsTrue(bResult);
        }
    }
}
